import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


def main():
    array1 = np.array([1, 2, 3, 4, 5])
    print(f'array1: {array1}')

    array2 = np.array([[1, 2, 3], [4, 5, 6]])
    print(f'array2: {array2}')

    # 使用arange函数，指定取值范围和跨度创建数组对象
    array3 = np.arange(0, 20, 2)
    print(f'array3: {array3}')

    # 使用linspace函数，用指定范围和元素个数创建数组对象，生成等差数列
    array4 = np.linspace(-1, 1, 11)
    print(f'array4: {array4}')

    # 使用logspace函数，生成等比数列
    array5 = np.logspace(1, 10, num=10, base=2)
    print(f'array5: {array5}')

    # 通过fromstring函数从字符串提取数据创建数组对象
    array6 = np.fromstring('1, 2, 3, 4, 5', sep=',', dtype='i8')
    print(f'array6: {array6}')

    # 'i8' 表示一个 64 位的整数(int64)
    gen = fib(20)
    array7 = np.fromiter(gen, dtype='i8')
    print(f'array7: {array7}')

    # 使用numpy.random模块的函数生成随机数创建数组对象，产生10个$[0, 1)$范围的随机小数
    array8 = np.random.rand(10)
    print(f'array8: {array8}')

    # 产生$[0, 1)$范围的随机小数构成的3行4列的二维数组，代码：
    array11 = np.random.rand(3, 4)
    print(f'array11: {array11}')

    array12 = np.random.randint(1, 100, (3, 4, 5))
    print(f'array12: {array12}')

    array13 = np.zeros((3, 4))
    print(f'array13: {array13}')

    array15 = np.full((3, 4), 10)
    print(f'array15: {array15}')

    array15_1 = np.eye(4)
    print(f'array15_1: {array15_1}')

    array16 = plt.imread('../study-day61&65/baidu.png')
    print(f'array16: {array16}')

    array19 = np.arange(1, 10)
    print(f'array19: {array19}')
    print(array19[0], array19[array19.size - 1])
    # print(array19[-array20.size], array19[-1])

    array20 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    print(array20[-1][-1])
    print(array20[:2, 1:])
    print(array20[2, :])
    print(array20[2:, :])
    print(array20[:, :2])
    # :: 语法表示步长
    print(array20[::2, ::2])
    print(array20[::-2, ::-2])


def fib(how_many):
    a, b = 0, 1
    for _ in range(how_many):
        a, b = b, a + b
        yield a


if __name__ == '__main__':
    main()
